package com.system.dao;

import com.am.base.BaseDao;
import com.system.uitls.CommonUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public class DrugRateDao extends BaseDao
{
  public Map<String, String> update(Map<String, Object> map)
  {
    Map result = new HashMap();
    String rate = CommonUtil.nullToEmptyString(map.get("rate"));
    List sqlList = new ArrayList();
    List params = new ArrayList();
    try
    {
      sqlList.add("UPDATE sys_config SET drug_percentage=? WHERE id=1");
      params.add(new Object[] { rate });

      batchInTransaction(sqlList, params);
      result.put("type", "success");
      result.put("value", "修改成功");
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
      result.put("type", "fail");
      result.put("value", "修改失败");
    }

    return result;
  }

  public String queryRate()
  {
    String sql = "SELECT drug_percentage FROM sys_config WHERE id=1";
    List list = getSimpleJdbc().queryForList(sql, new Object[0]);
    Map map = (Map)list.get(0);
    String rate = CommonUtil.nullToEmptyString(map.get("drug_percentage"));
    return rate;
  }
}